﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MusicAcademy
{
    public partial class ListOfClasses : Form
    {
        public int SelectedID = -1;
        public string ClassNumber { get; set; }

        public ListOfClasses()
        {
            InitializeComponent();
        }

        private void RefreshGrid()
        {
            classTableAdapter.Fill(musicAcademyDataSet.Class, Program.academyID, txtClassNumber.Text);
        }

        private void ListOfClasses_Load(object sender, EventArgs e)
        {
            RefreshGrid();
            grdClass.ClearSelection();

        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (grdClass.SelectedRows.Count > 0)
            {
                SelectedID = Convert.ToInt32(grdClass.SelectedRows[0].Cells["ID"].Value);
                ClassNumber = grdClass.SelectedRows[0].Cells["classNumber"].Value.ToString();
                DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("لطفا یک کلاس را انتخاب نمایید.", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            SelectedID = -1;
            DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }

        private void grdClass_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (grdClass.SelectedRows.Count > 0)
            {
                SelectedID = Convert.ToInt32(grdClass.SelectedRows[0].Cells["ID"].Value);
                ClassNumber = grdClass.SelectedRows[0].Cells["classNumber"].Value.ToString();
                DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("لطفا یک کلاس را انتخاب نمایید.", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }

        private void txtClassNumber_TextChanged(object sender, EventArgs e)
        {
            RefreshGrid();
        }


    }
}
